package com.app.ctrl;

import com.app.mapper.TestKeyMapper;
import com.app.pojo.TestKey;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Key;
import java.util.List;

@RestController
public class TestCtrl {

    @Autowired
    private TestKeyMapper testkeyMapper;

    @RequestMapping("/")
    public void test(){
        System.err.println("成功接受请求");
    }

    @RequestMapping("/testkey")
    public void testkey(){
        //查询testkey里的所有信息,不带任何条件进行查询
        List<TestKey> testKeys = testkeyMapper.selectList(null);
        for (TestKey k : testKeys){
            System.out.println(k);
        }
    }

    @RequestMapping("/testkey2")
    public void testkey2(TestKey key) {
        //添加一个testkey
        int insert = testkeyMapper.insert(key);
        System.out.println("成功插入数据量：" + insert);
    }

    @RequestMapping("/testkey3")
    public void testkey3(){
        Page<TestKey> page = new Page<>();
        page.setSize(5l);
        //page.setCurrent(2l);
        //查询testkey里的所有信息,以分页的形式
        QueryWrapper<TestKey> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("key1","z");
        Page<TestKey> testKeyPage = testkeyMapper.selectPage(page, queryWrapper);
        List<TestKey> list = testKeyPage.getRecords();
        for (TestKey key : list){
            System.out.println(key);
        }
        System.out.println("------------------------------------");
        System.err.println("当前第几页："+testKeyPage.getCurrent());
        System.err.println("每页多少条"+testKeyPage.getSize());
        System.err.println("总共的条数："+testKeyPage.getTotal());

    }
}
